<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <%@ include file="/commons/basejs.jsp" %>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>标签管理</title>
    <script type="text/javascript">

    </script>
</head>
<body>
<script type="text/javascript">
    var configCategoryDataGrid;
    var configManageDataGrid;
    $(function() {
        configCategoryDataGrid = $('#configCategoryDataGrid').datagrid({
            url : '${path }/configCategory/dataGrid.do',
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            sortName : 'id',
            sortOrder : 'asc',
            pageSize : 20,
            pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
            frozenColumns : [ [ {
                width : '100',
                title : 'id',
                field : 'id',
                sortable : true
            }, {
                width : '80',
                title : '名称',
                field : 'name',
                sortable : true
            } , {
                width : '80',
                title : '排序号',
                field : 'ord',
                sortable : true
            }, {
                width : '60',
                title : '状态',
                field : 'status',
                sortable : true,
                formatter : function(value, row, index) {
                    switch (value) {
                        case 0:
                            return '停用';
                        case 1:
                            return '启用';
                    }
                }
            }, {
                field : 'action',
                title : '操作',
                width : 200,
                formatter : function(value, row, index) {
                    var str = '';
                    <shiro:hasPermission name="/configCategory/edit.do">
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="configCategory-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="editConfigCategoryFun(\'{0}\');" >编辑</a>', row.id);
                    </shiro:hasPermission>
                    <shiro:hasPermission name="/configCategory/delete.do">
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="configCategory-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="deleteConfigCategoryFun(\'{0}\');" >删除</a>', row.id);
                    </shiro:hasPermission>
                    return str;
                }
            } ] ],
            onClickRow: function (index, row) {//运用单击事件实现一行的编辑结束，在该事件触发前会先执行onAfterEdit事件
                console.log("id:" + row.id);
                configManageSearch();
            },
            onLoadSuccess:function(data){
                $('.configCategory-easyui-linkbutton-edit').linkbutton({text:'编辑'});
                $('.configCategory-easyui-linkbutton-del').linkbutton({text:'删除'});
                loadConfigManage();
            },


            toolbar : '#configCategoryToolbar'
        });

    });
    function loadConfigManage() {
        console.log("1111111111111");
        configManageDataGrid = $('#configManageDataGrid').datagrid({
            url : '${path }/configManage/dataGrid.do',
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            sortName : 'id',
            sortOrder : 'asc',
            pageSize : 20,
            pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
            frozenColumns : [ [ {
                width : '100',
                title : 'id',
                field : 'id',
                sortable : true
            },  {
                width : '150',
                title : '名称',
                field : 'des'
            },  {
                width : '80',
                title : 'key',
                field : 'k'
            }, {
                width : '80',
                title : 'value',
                field : 'v'
            } , {
                width : '60',
                title : '状态',
                field : 'status',
                sortable : true,
                formatter : function(value, row, index) {
                    switch (value) {
                        case 0:
                            return '停用';
                        case 1:
                            return '启用';
                    }
                }
            }, {
                field : 'action',
                title : '操作',
                width : 200,
                formatter : function(value, row, index) {
                    var str = '';
                    <shiro:hasPermission name="/configManage/edit.do">
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="configManage-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="editConfigManageFun(\'{0}\');" >编辑</a>', row.id);
                    </shiro:hasPermission>
                    <shiro:hasPermission name="/configManage/delete.do">
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="configManage-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="deleteConfigManageFun(\'{0}\');" >删除</a>', row.id);
                    </shiro:hasPermission>
                    return str;
                }
            } ] ],
            onLoadSuccess:function(data){
                $('.configManage-easyui-linkbutton-edit').linkbutton({text:'编辑'});
                $('.configManage-easyui-linkbutton-del').linkbutton({text:'删除'});
            },
            toolbar : '#configManageToolbar'
        });
    }

    function addConfigManageFun() {
        parent.$.modalDialog({
            title : '添加',
            width : 500,
            height : 300,
            href : '${path }/configManage/addPage.do',
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = configManageDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#configManageAddForm');
                    f.submit();
                }
            } ]
        });
    }

    function editConfigManageFun(id) {
        if (id == undefined) {
            var rows = configManageDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {
            configManageDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.modalDialog({
            title : '编辑',
            width : 500,
            height : 300,
            href : '${path }/configManage/editPage.do?id=' + id,
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = configManageDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#configManageEditForm');
                    f.submit();
                }
            } ]
        });
    }

    function deleteConfigManageFun(id) {
        if (id == undefined) {//点击右键菜单才会触发这个
            var rows = configManageDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {//点击操作里面的删除图标会触发这个
            configManageDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.messager.confirm('询问', '您确定要删除当前配置？', function(b) {
            if (b) {
                progressLoad();
                $.post('${path }/configManage/delete.do', {
                    id : id
                }, function(result) {
                    if (result.success) {
                        parent.$.messager.alert('提示', result.msg, 'info');
                        configManageDataGrid.datagrid('reload');
                    }
                    progressClose();
                }, 'JSON');
            }
        });
    }

    //查询标签
    function configManageSearch(){
        var queryParams = {};

        var select = $("#configCategoryDataGrid").datagrid("getSelected");
        if (select == null) {
            queryParams.configCategoryId ="";
        }else{
            queryParams.configCategoryId =select.id;
        }


            queryParams.statusType =$("#statusSearchWord").combobox('getValue');
            queryParams.keySearchWord = $("#keySearchWord").val();
            queryParams.valueSearchWord =$("#valueSearchWord").val();
        var options = $("#configManageDataGrid").datagrid('getPager').data("pagination").options;
        options.pageNumber = 1;
        //重新加载
        $("#configManageDataGrid").datagrid('options').url = "${path }/configManage/dataGrid.do";
        $("#configManageDataGrid").datagrid('options').queryParams = queryParams;
        $("#configManageDataGrid").datagrid('reload');
    }
    function resetSearch() {
        $('#configCategoryId').combobox('clear');
        $("#keySearchWord").val("");
        $("#valueSearchWord").val("");
        $("#statusSearchWord").combobox("setValue","");
    }



    function addConfigCategoryFun() {
        parent.$.modalDialog({
            title : '添加',
            width : 500,
            height : 300,
            href : '${path}/configCategory/addPage.do',
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = configCategoryDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#configCategoryAddForm');
                    f.submit();
                }
            } ]
        });
    }

    function editConfigCategoryFun(id) {
        if (id == undefined) {
            var rows = configCategoryDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {
            configCategoryDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.modalDialog({
            title : '编辑',
            width : 500,
            height : 300,
            href : '${path }/configCategory/editPage.do?id=' + id,
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = configCategoryDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#configCategoryEditForm');
                    f.submit();
                }
            } ]
        });
    }

    function deleteConfigCategoryFun(id) {
        if (id == undefined) {//点击右键菜单才会触发这个
            var rows = configCategoryDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {//点击操作里面的删除图标会触发这个
            configCategoryDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.messager.confirm('询问', '您是否要删除当前角色？', function(b) {
            if (b) {
                progressLoad();
                $.post('${path }/configCategory/delete.do', {
                    id : id
                }, function(result) {
                    if (result.success) {
                        parent.$.messager.alert('提示', result.msg, 'info');
                        configCategoryDataGrid.datagrid('reload');
                    }
                    progressClose();
                }, 'JSON');
            }
        });
    }

    function grantConfigCategoryFun(id) {
        if (id == undefined) {
            var rows = configCategoryDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {
            configCategoryDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
    }
    //查询标签
    function ConfigCategorySearch(){
        var queryParams = {};
        queryParams.statusType =$("#configCategoryname").val();
        queryParams.configCategoryStatus =$('#configCategoryord').combobox('getValue');
        var options = $("#configCategoryDataGrid").datagrid('getPager').data("pagination").options;
        options.pageNumber = 1;
        //重新加载
        $("#configCategoryDataGrid").datagrid('options').url = "${path }/configCategory/dataGrid.do";
        $("#configCategoryDataGrid").datagrid('options').queryParams = queryParams;
        $("#configCategoryDataGrid").datagrid('reload');
    }
    function resetConfigCategorySearch() {
        $('#configCategoryname').val("");
        $("#configCategoryord").combobox('clear');
    }
    
    function addToRedisFun() {
        $.get("${path }/configManage/addToRedis.do",{},function (data) {
            $.messager.alert('提示', data.msg, 'info');
        });

    }

</script>
<div class="easyui-layout" fit="true">
    <div data-options="region:'west',border:true" style="width:40%;">
        <table id="configCategoryDataGrid" data-options="fit:true,border:false"></table>
    </div>
    <div data-options="region:'center',border:true"  style="width:60%;">
        <table id="configManageDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
<div id="configManageToolbar" style="display: none;">
    <shiro:hasPermission name="/configManage/add.do">
        <a onclick="addConfigManageFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-plus icon-green'">添加</a>
    </shiro:hasPermission>
    <shiro:hasPermission name="/configManage/addToRedis.do">
      <a onclick="addToRedisFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-loop icon-green'">同步到Redis</a>
    </shiro:hasPermission>


    状态:<select id="statusSearchWord" name="status" class="easyui-combobox" data-options="width:60,editable:false,panelHeight:'auto'">
            <option value="">全部</option>
            <option value="1">启用</option>
            <option value="0">停用</option>
        </select>
    
    key:<input type="text" id="keySearchWord" name="keySearchWord"/>

    value:<input type="text" id="valueSearchWord" name="valueSearchWord"/>


    <input type="button" class="easyui-linkbutton " value="重置" onclick="resetSearch();"/>
    &nbsp;
    <input type="button" class="easyui-linkbutton" value="搜索" onclick="configManageSearch();"/>

</div>
<div id="configCategoryToolbar" style="display: none;">
    <shiro:hasPermission name="/configCategory/add.do">
        <a onclick="addConfigCategoryFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-plus icon-green'">添加</a>

        状态:<select id="configCategoryord" name="ord" class="easyui-combobox" data-options="width:60,editable:false,panelHeight:'auto'">
        <option value="">全部</option>
        <option value="1">启用</option>
        <option value="0">停用</option>
        </select>
        名称:<input type="text" id="configCategoryname" name="name"/>

        <input type="button" class="easyui-linkbutton " value="重置" onclick="resetConfigCategorySearch();"/>
        &nbsp;
        <input type="button" class="easyui-linkbutton" value="搜索" onclick="ConfigCategorySearch();"/>

    </shiro:hasPermission>
</div>
</body>
</html>